#include<bits/stdc++.h>
#define int long long
//#define endl '\n'
using namespace std;
const int inf=0x3f3f3f3f3f3f3f3f;
int n,mod,ans,cnt;
//int e[10][10];
//int fa[10];
//int find(int x)
//{
//	if(fa[x]==x)return x;
//	return fa[x]=find(fa[x]);
//}
//int merge(int u,int v)
//{
//	u=find(u),v=find(v);
//	if(u==v)return 1;
//	fa[u]=v;
//	cnt--;
//	return 0;
//}
////vector<int>vec;
//void dfs2(int x)
//{
//	ans++;
////	for ( auto v:vec )cout << v << "->";
////	cout << x << endl;
////	vec.push_back(x);
//	for ( int i = 1 ; i <= n ; i++ )if(e[x][i])dfs2(i);
////	vec.pop_back();
//}
//void calc()
//{
//	for ( int i = 1 ; i <= n ; i++ )fa[i]=i;
//	cnt=n;
//	for ( int i = 1 ; i <= n ; i++ )
//	{
//		for ( int j = 1 ; j <= n ; j++ )
//		{
//			if(e[i][j])if(merge(i,j))return;
//		}
//	}
//	if(cnt!=1)return;
////	cout << "edges:\n";
////	for ( int i = 1 ; i <= n ; i++ )
////	{
////		for ( int j = 1 ; j <= n ; j++ )
////		{
////			if(e[i][j])cout << i << " to " << j << endl;
////		}
////	}
//	for ( int i = 1 ; i <= n ; i++ )dfs2(i);
//}
//void dfs(int x,int y)
//{
////	cout << x << " " << y << endl;
//	if(x==n+1)return calc(),void();
//	int nx,ny;
//	if(y==n)
//	{
//		nx=x+1;
//		ny=1;
//	}else nx=x,ny=y+1;
//	dfs(nx,ny);
//	if(x==y||e[y][x])return;
//	e[x][y]=1;
//	dfs(nx,ny);
//	e[x][y]=0;
//}
int res[10]={0,1,6,66,1064,22680,602352,19176304};
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("tree.in","r",stdin);
	freopen("tree.out","w",stdout);
	cin >> n >> mod;
	if(mod==2)return cout << 0,0;
	cout << res[n]%mod;
//	dfs(1,1);
//	cout << ans;
	return 0;
}//30
// 1 6 66 1064 22680 602352 19176304

